package com.aistar.controller;
<<<<<<< HEAD
import com.aistar.pojo.Member;
import com.aistar.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;

@Controller //<bean id = "memberController" class="com.aistar.controller.MemberController">
public class MemberController {
    @Autowired
    @Qualifier(value = "memberServiceImpl")
    private MemberService memberService;
    private String memberName;
    private String memberJob;
    private Integer memberAge;

    public MemberController() {
    }

    public MemberController(MemberService memberService, String memberName, String memberJob, Integer memberAge) {
        this.memberService = memberService;
        this.memberName = memberName;
        this.memberJob = memberJob;
        this.memberAge = memberAge;
    }

    public void setMemberService(MemberService memberService) {
        this.memberService = memberService;
    }

    public void setMemberName(String memberName) {
        this.memberName = memberName;
    }

    public void setMemberJob(String memberJob) {
        this.memberJob = memberJob;
    }

    public void setMemberAge(Integer memberAge) {
        this.memberAge = memberAge;
    }

    public Member getById(int id) {
        System.out.println("MemberController.getById");
        return memberService.getById(id);
    }
    //注册
    public boolean save(Member member){
        System.out.println("controller 添加新用户");
        return memberService.save(member);
    }
    //注册
    public void delete(int id){
        System.out.println("controller 删除新用户");
        memberService.delete(id);
    }

    //登录
    public void login(String memberName, String memberPwd) {
        System.out.println("controller 添加新用户");
        memberService.getByOthers(memberName,memberPwd);
=======

import com.aistar.pojo.Member;
import com.aistar.service.MemberService;
import com.aistar.service.impl.MemberServiceImpl;
import com.aistar.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.io.PrintWriter;

@Controller
public class MemberController {

    @Autowired
    private MemberService memberService;

    @RequestMapping("member/save")
    public String save() {
        return "save success";
    }


    @GetMapping("member/get/{id}")
    public Member getById(@PathVariable("id") int id) {
        return this.memberService.getById(id);
    }

    //获得手机验证码
    @PostMapping("member/getcode")
    @ResponseBody
    public JsonResult getSsmCode(long telno) { //1. 验证手机号码是否存在
         System.out.println("telno:" + telno);

        JsonResult jsonResult = memberService.getByTelno(telno);
        System.out.println("getcode:" + jsonResult);
        if (jsonResult.getCode() == 1) { //2. 手机号不存在
             return jsonResult;

        } else {
            System.out.println("用户存在，可以登录");
            //2. 发送验证码
            String code = "666666";// GetMessageCode.getCode(telnoStr);
            return new JsonResult(0,"用户存在，可以登录",code);
        }
    }

    //登录
    @RequestMapping("member/login/{telno}")
    public ModelAndView login(@PathVariable("telno") long telno, HttpServletRequest request){
        ModelAndView mav = new ModelAndView();

       JsonResult jsonResult = memberService.getByTelno(telno);
       Member member = (Member)jsonResult.getData();
        if(member!=null){
            request.getSession().setAttribute("loginUserName",member.getMemberName());
            request.getSession().setAttribute("loginUserId",member.getMemberId());
            request.getSession().setAttribute("loginUser",member);
        }
        mav.setViewName("index"); // /index.jsp
        return mav ;
>>>>>>> 79297cf758ff388ed3ea7d02640b718856076aad
    }
}


